package com.chenfan.process.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chenfan.process.entity.dto.ApprovalTemplateQueryDTO;
import com.chenfan.process.entity.po.ApprovalTemplatePo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author K
 * @date 2021/3/17
 */
public interface ApprovalTemplateRepository extends BaseMapper<ApprovalTemplatePo> {

    @Select("<script>" + "select t.* from  chenfan_paas_approval_template_po t, process_approval_template_snapshot s\n"
        + "where t.approval_snapshot_id =  s.id\n"
        + "<when test=\"template.title != null and template.title != '' \">and t.title like concat('%', #{template.title}, '%') </when>\n"
        + "<when test=\"template.createName != null and template.createName != '' \"> and t.create_name like concat('%',#{template.createName}, '%')</when>\n"
        + "<when test=\"template.updateName != null and template.updateName != '' \"> and t.update_name like concat('%',#{template.updateName}, '%')</when>\n"
        + "<when test=\"template.approvalName != null and template.approvalName != '' \">and s.approval_name like concat('%',#{template.approvalName}, '%')</when>\n"
        + "<when test=\"template.belongIdList != null and template.belongIdList.size() > 0\">and t.belong_id in  <foreach item='item' index='index' collection='template.belongIdList' open='(' separator=',' close=')'> #{item} </foreach>\n" +
            "</when>\n"
        + "and t.deleted_flag = 0 and s.deleted_flag = 0\n"
        + "order by t.create_time desc" + "</script>")
    List<ApprovalTemplatePo> pageApprovalTemplate(@Param("template") ApprovalTemplateQueryDTO template,
        Page<ApprovalTemplatePo> page);
}
